<script setup>
import {saveApi} from "@/api/AssetsApi";
import MyForm from "@/components/MyForm.vue";
import {shallowReactive, shallowRef} from "vue";
import {RULE} from "@/const";
import MyHead from "@/components/MyHead.vue";
import MyNav from "@/components/MyNav.vue";
import router from "@/router";

// 表单数据 + 表单规则
let items = shallowRef([
  {'label': '资产名称', 'prop': 'title'},
  {'label': '资产图片','prop': 'picture'},


  {'label': '资产价格', 'prop':'price'},
  {'label': '价格单位', 'prop': 'priceUnit'},

  {'label': '库存剩余', 'prop': 'stock'},
  {'label': '库存单位', 'prop': 'stockUnit'},
  {'label': '总数量', 'prop': 'total'},


  {'label': '资产描述', 'prop': 'info', 'type': 'textarea'},
]);
let data = shallowReactive({
  'capacity': 0,
});
let rules = {
  'info': RULE.COMMON_INFO,
  'title': RULE.COMM_TITLE,
};

function success() {
  setTimeout(() => router.push('/rms/Assets'), 1000);
}

</script>

<template>

  <my-nav :items="[
    {'icon': 'User', 'label': '资产管理'},
    {'icon': 'User', 'label': '资产列表', 'url': '/rms/Assets'},
    {'icon': 'User', 'label': '添加资产'},
  ]"/>

  <div className="assets-insert-body">
    <my-form type="insert"
             :items="items"
             :data="data"
             :rules="rules"
             :api="saveApi"
             :fn="success"
             :span='2'/>
  </div>

</template>

<style scoped lang="scss">
.assets-insert-body {
  width: 800px;
  margin-top: 50px;
}
</style>